home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 05.zip
/
BS1 part 5
/
PDraw3.0.adf
/
pdraw_rex.lzh
/
PlotFunction.pdrx
< prev
next >
Wrap
Text File
|
1992-06-17
|
2KB
|
95 lines
/*
@N
This Genie will plot a mathematical function in terms of x and y on the screen
*/
signal on error
signal on syntax
msg = PDSetup.rexx(2,0)
units = getclip(pds_units)
if msg ~= 1 then exit_msg(msg)
cr = '0a'x
function = getclip(pduser_function)
start = getclip(pduser_fstart)
stop = getclip(pduser_fstop)
npoints = getclip(pduser_fnpoints)
scale = getclip(pduser_fnscale)
form = "x0:"start||cr"xn:"stop||cr"n:"npoints||cr"f(x):"function||cr"scale:"scale
form = pdm_getform("Enter function of x", 30, form)
if form= "" then exit
parse var form start '0a'x stop '0a'x numpoints '0a'x function '0a'x scale
if ~(datatype(start, n) & datatype(stop, n) & datatype(numpoints, n)) then
exit_msg("Invalid Entry")
if units = 3 then do
start = pdm_ConvertUnits(units, 1, start)
stop = pdm_ConvertUnits(units, 1, stop)
end
call setclip(pduser_function, function)
call setclip(pduser_fstart, start)
call setclip(pduser_fstop, stop)
call setclip(pduser_fnpoints, numpoints)
call setclip(pduser_fnscale, scale)
call pdm_abortplot()
p = pdm_getpagesize()
w = word(p,1)
h = word(p,2)
scale = scale * w / (stop-start)
ox = -start * w / (stop-start)
oy = h / 2
/* draw axis */
call pdm_setfillpattern(,0)
call pdm_setlinecolor(,"Black")
call pdm_initplot()
if (ox >= 0) & (ox <= w) then do
call pdm_plotline(ox" 0,"ox" "h", "ox" "oy", 0 "oy", "w" "oy)
end
else do
call pdm_plotline("0 "oy", "w" "oy)
end
call pdm_endplot()
maxy = h/scale
miny = -maxy
call pdm_initplot(ox,oy,scale,-scale,0)
call pdm_setlinecolor(,"Red")
inc = (stop - start) / numpoints
do x = start to stop by inc
interpret "y = "function
y = 1 * y
if y < miny then y = miny
if y > maxy then y = maxy
call pdm_plotsmooth(x" "y)
end
call pdm_endplot()
exit_msg()
exit_msg: procedure expose units
do
parse arg message
if message ~= '' then call pdm_Inform(1,message,)
call pdm_SetUnits(units)
call pdm_AutoUpdate(1)
exit
end
error:
syntax:
exit_msg("Function failed due to error: "errortext(rc))